/**
 * 
 */
package com.controller.broker;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import com.HOPP.ClientHOPP;
import com.dao.Flight;

/**
 * @author Phillip
 * 
 */
public class BrokerSHOPP implements ClientHOPP {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}

	private BrokerCHOPP[] connectors;

	public BrokerSHOPP() {
		connectors = new BrokerCHOPP[3];
		for (int i = 0; i < 3; i++) {
			connectors[i] = new BrokerCHOPP(i + 1);
		}
	}

	@Override
	public List<String> queryCity() {
		List<String> tempList = new ArrayList<String>();
		for (int i = 0; i < 3; i++) {
			tempList.addAll(connectors[i].queryCity());
		}
		HashSet<String> h = new HashSet<String>(tempList);
		tempList.clear();
		tempList.addAll(h);
		return tempList;
	}

	@Override
	public List<Flight> queryFlights(String deptString, String destString, String deptDateString, String returnDateString) {
		List<Flight> flights = new ArrayList<Flight>();
		for (int i = 0; i < 3; i++) {
			flights.addAll(connectors[i].queryFlights(deptString, destString, deptDateString, returnDateString));
		}
		return flights;
	}

	@Override
	public String book(int airline, String flightNoString1, String deptString, String classString1, String flightNoString2, String returnString,
			String classString2, String nameString, String creditString) {

		return connectors[airline - 1].book(airline, flightNoString1, deptString, classString1, flightNoString2, returnString, classString2,
				nameString, creditString);
	}

	@Override
	public String queryRates(int airline, String flightString, String deptDateString, String classString) {

		return connectors[airline - 1].queryRates(airline, flightString, deptDateString, classString);
	}

	public void bye() {
		for (int i = 0; i < 3; i++) {
			connectors[i].sendBYE();
		}
	}

	@Override
	public List<String> queryAirline(String deptString, String dsctString) {

		List<String> airlines = new ArrayList<String>();
		for (int i = 0; i < 3; i++) {
			airlines.add(connectors[i].queryAirline(deptString, dsctString));
		}
		return airlines;
	}

}
